package com.superzqb.asus.superzqbFragment.superzqbSave.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbUtil.RoundImageView;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by asus on 2017/4/19.
 */

public class MyAimAdapter extends BaseAdapter {
    private ArrayList<Map<String,Object>> items;
    private Context context;
    public MyAimAdapter(Context context, ArrayList<Map<String, Object>> lists){
        this.context=context;
        this.items=lists;
    }
    @Override
    public int getCount() {
        return items==null?0:items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void setList(ArrayList<Map<String, Object>> list){
        this.items=list;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.save_my_aim_item,parent,false);
            convertView.setTag(new MyAimAdapter.ViewHolder(convertView));
        }
        MyAimAdapter.ViewHolder holder=(MyAimAdapter.ViewHolder) convertView.getTag();
        Map<String,Object> map=items.get(position);
        holder.aimGoods.setText("目标商品："+map.get("addGoods").toString());
        holder.money.setText("金额："+map.get("money").toString()+"(元)");
        holder.progress.setText("已完成："+map.get("progress").toString()+"%");
        holder.toSave.setText("剩余攒钱次数："+map.get("toSave").toString());
        holder.saved.setText("已攒："+map.get("saved").toString()+"(元)");
        switch (position){
            case 0:
                holder.pic.setImageDrawable(context.getResources().getDrawable(R.mipmap.aim1));
                break;
            case 1:
                holder.pic.setImageDrawable(context.getResources().getDrawable(R.mipmap.aim2));
                break;
            case 2:
                holder.pic.setImageDrawable(context.getResources().getDrawable(R.mipmap.aim3));
                break;

        }

        return convertView;
    }


    class ViewHolder{
        private TextView aimGoods,money,progress,saved,toSave;
        private RoundImageView pic;
        private ViewHolder(View view){
            aimGoods=(TextView)view.findViewById(R.id.aimGoods);
            money=(TextView)view.findViewById(R.id.money);
            progress=(TextView)view.findViewById(R.id.progress);
            saved=(TextView)view.findViewById(R.id.saved);
            toSave=(TextView)view.findViewById(R.id.toSave);
            pic=(RoundImageView)view.findViewById(R.id.pic);

        }
    }
}
